<template>
  <a-layout class="layout-container">
    <a-layout-sider
      v-model:collapsed="collapsed"
      :trigger="null"
      collapsible
      class="sidebar"
      width="250"
    >
      <div class="logo">
        <img src="@/assets/logo.png" alt="Logo" />
        <span v-if="!collapsed">RFID药品追溯系统</span>
      </div>
      <a-menu
        mode="inline"
        v-model:selectedKeys="selectedKeys"
        theme="dark"
        @click="handleMenuClick"
      >
        <a-menu-item key="/dashboard">
          <template #icon><dashboard-outlined /></template>
          <span>系统总览</span>
        </a-menu-item>
        <a-menu-item key="/medicine-management">
          <template #icon><medicine-box-outlined /></template>
          <span>药品管理</span>
        </a-menu-item>
        <a-menu-item key="/trace">
          <template #icon><apartment-outlined /></template>
          <span>药品追溯</span>
        </a-menu-item>
        <a-menu-item key="/verification">
          <template #icon><safety-certificate-outlined /></template>
          <span>药品验证</span>
        </a-menu-item>
        <a-menu-item key="/rfid-scan">
          <template #icon><scan-outlined /></template>
          <span>RFID扫描</span>
        </a-menu-item>
      </a-menu>
    </a-layout-sider>
    <a-layout>
      <a-layout-header class="header">
        <menu-unfold-outlined
          v-if="collapsed"
          class="trigger"
          @click="() => (collapsed = !collapsed)"
        />
        <menu-fold-outlined
          v-else
          class="trigger"
          @click="() => (collapsed = !collapsed)"
        />
        <div class="header-title">
          基于RFID的药品追溯防伪系统
        </div>
        <div class="header-actions">
          <a-dropdown>
            <a-button type="text">
              <template #icon><user-outlined /></template>
              管理员
              <down-outlined />
            </a-button>
            <template #overlay>
              <a-menu>
                <a-menu-item key="profile">
                  <user-outlined />个人信息
                </a-menu-item>
                <a-menu-item key="settings">
                  <setting-outlined />系统设置
                </a-menu-item>
                <a-menu-divider />
                <a-menu-item key="logout">
                  <logout-outlined />退出登录
                </a-menu-item>
              </a-menu>
            </template>
          </a-dropdown>
        </div>
      </a-layout-header>
      <a-layout-content class="content">
        <router-view v-slot="{ Component }">
          <transition name="fade" mode="out-in">
            <component :is="Component" />
          </transition>
        </router-view>
      </a-layout-content>
    </a-layout>
  </a-layout>
</template>

<script setup lang="ts">
import { ref, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import {
  MenuUnfoldOutlined,
  MenuFoldOutlined,
  DashboardOutlined,
  MedicineBoxOutlined,
  ApartmentOutlined,
  SafetyCertificateOutlined,
  ScanOutlined,
  UserOutlined,
  SettingOutlined,
  LogoutOutlined,
  DownOutlined
} from '@ant-design/icons-vue'

const router = useRouter()
const route = useRoute()
const collapsed = ref(false)
const selectedKeys = ref<string[]>(['/dashboard'])

const handleMenuClick = ({ key }: { key: string }) => {
  router.push(key)
}

onMounted(() => {
  selectedKeys.value = [route.path]
})

watch(
  () => route.path,
  (path) => {
    selectedKeys.value = [path]
  }
)
</script>

<style scoped>
.layout-container {
  min-height: 100vh;
}

.sidebar {
  box-shadow: 2px 0 6px rgba(0, 21, 41, 0.35);
  z-index: 10;
}

.logo {
  height: 64px;
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  color: white;
  font-size: 18px;
  font-weight: 600;
}

.logo img {
  height: 32px;
  width: 32px;
}

.header {
  padding: 0 16px;
  background: #fff;
  display: flex;
  align-items: center;
  box-shadow: 0 1px 4px rgba(0, 21, 41, 0.08);
  z-index: 9;
}

.trigger {
  font-size: 18px;
  cursor: pointer;
  transition: color 0.3s;
  padding: 0 12px;
}

.trigger:hover {
  color: #1890ff;
}

.header-title {
  flex: 1;
  font-size: 18px;
  font-weight: 500;
  color: rgba(0, 0, 0, 0.85);
  margin-left: 16px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.content {
  margin: 24px;
  padding: 24px;
  background: #fff;
  min-height: 280px;
  overflow: auto;
  border-radius: 2px;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s ease;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style> 